package com.zt.questionnaire;

import com.zt.questionnaire.common.annotation.EnableCache;
import com.zt.questionnaire.common.annotation.EnableCommon;
import com.zt.questionnaire.common.utils.AssertUtils;
import com.zt.questionnaire.service.excel.HExcelQuestionnaireService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 问卷
 *
 * @author funnywus
 */
@EnableCommon // 通用注解
@EnableCache
@EnableScheduling
@EnableAsync //开启异步
@ImportResource(locations = {"classpath:spring/spring-datasource.xml"})
@Slf4j
@SpringBootApplication
public class QuestionnaireApplication implements CommandLineRunner {

    @Autowired
    private HExcelQuestionnaireService excelQuestionnaireService;

    public static void main(String[] args) {
        log.info("问卷服务 启动中 -------------------------");
        SpringApplication.run(QuestionnaireApplication.class, args);
        log.info("问卷服务 启动成功 -------------------------");
    }

    @Override
    public void run(String... args) throws Exception {
        // 加载excel
        loadExcel();
    }

    /**
     * 加载excel
     */
    private void loadExcel() throws Exception {
        boolean is = true;
        is = excelQuestionnaireService.readExcel();

        if (!is) {
            AssertUtils.newThrow("excel数据加载异常");
        }
    }

}
